import mockjs, { Random } from 'mockjs';
import _ from 'lodash';

const responseData = {
  success: true,
  data: Object,
  msg: null,
};

const userTmp = {
  id: '@natural',
  userName: null,
  pwd: '@word',
  name: '@cname',
  tel: '13871911154',
  status: '@integer(0, 1)',
  update_time: '@datetime',
  role_uid: '@guid',
};

export default {
  'POST /myapi/account/login': (req, res) => {
    const { username, password } = req.body;
    const result = { ...responseData };
    if (username) {
      const user = mockjs.mock(userTmp);
      user.userName = username;
      result.data = { user, token: Random.guid() };
    } else {
      result.success = false;
      result.msg = 'username is missing!';
    }
    res.send(result);
  },
};
